# Maintainer: David Runge <dvzrv@archlinux.org>

_name=iwlib
pkgname=python-iwlib
pkgver=1.7.0
pkgrel=5
pkgdesc='Python module to interface with iwlib'
arch=('loong64' 'x86_64')
url="https://github.com/nathan-hoad/python-iwlib"
license=('GPL2')
depends=('python-cffi' 'wireless_tools')
makedepends=('python-setuptools')
checkdepends=('python-pytest')
source=("https://files.pythonhosted.org/packages/source/${_name::1}/${_name}/${_name}-${pkgver}.tar.gz")
sha512sums=('c9909449f8b52fdd75e3135951fde2085abc5be622acd7be045a281f108b4f0bc5623f97b7b57a6b91f17170ea524bbb6a52626fa87877621873fe8b6b9f0bca')

prepare() {
  cd "${_name}-${pkgver}"
  # fixing include discovery: https://github.com/nhoad/python-iwlib/issues/11
  rm -v test/__init__.py
}

build() {
  cd "${_name}-${pkgver}"
  python setup.py build
}

check() {
  cd "${_name}-${pkgver}"
  local _py3_ver=$(python3 -c "import sys; print(str(sys.version_info.major)+str(sys.version_info.minor))")
  export PYTHONPATH="build/lib.linux-$CARCH-cpython-${_py3_ver}/:${PYTHONPATH}"
  py.test
}

package() {
  cd "${_name}-${pkgver}"
  python setup.py install --skip-build \
    --optimize=1 \
    --prefix=/usr \
    --root="${pkgdir}"
  # docs
  install -vDm 644 {AUTHORS,README.rst} \
    -t "${pkgdir}/usr/share/doc/${pkgname}/"
}
